package com.tom.commonframework.common.base.utils;

import android.view.View;

/**
 * Created by TomLeisen on 2018/3/4 下午5:03
 * Email: xy162162a@163.com
 * Description: 重写OnClickListener防止item快速连续点击，此工具类和ClickUtils效果一致
 */

public abstract class OnClickUtilsListener implements View.OnClickListener{
    // 两次点击按钮之间的点击间隔不能少于1000毫秒
    private static final int MIN_CLICK_DELAY_TIME = 1000;
    private static long lastClickTime;

    public abstract void onClickUtils(View view);

    @Override
    public void onClick(View view) {
        long curClickTime = System.currentTimeMillis();
        if((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
            // 超过点击间隔后再将lastClickTime重置为当前点击时间
            lastClickTime = curClickTime;
            onClickUtils(view);
        }
    }
}